package com.bw.liuyushan.zhuangao4_mvptest1.MVP.View.Fragment;

import android.content.Intent;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;

import com.blankj.utilcode.util.ToastUtils;
import com.bw.liuyushan.mvp_lib.View.BaseActivity;
import com.bw.liuyushan.mvp_lib.View.BaseFragment;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.UserBean;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Contrack.ICTest;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Model.BaseModelTest;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Presenter.BasePresenterTest;
import com.bw.liuyushan.zhuangao4_mvptest1.R;
import com.bw.liuyushan.zhuangao4_mvptest1.Utils.WindowUtils;

import org.greenrobot.eventbus.EventBus;

/**
 * ZhuanGao4_MVPTest1
 * file name is : regFragment
 * created by Ender on 2021/8/19 13:37.
 * author : 刘雨杉
 * Describe(作用):注册的Fragment 归属于UserActivity 注册 传值 跳转
 */
public class regFragment extends BaseFragment<BasePresenterTest> implements ICTest.C_ViewTest {
    private android.widget.EditText name2;
    private android.widget.EditText pass2;
    private android.widget.Button reg;
    private android.widget.Button gotoLogin;

    @Override
    public int bindLayout() {
        return R.layout.activity_register;
    }

    @Override
    public void initView() {
        //防止内存泄露
        ip = new BasePresenterTest(new BaseModelTest(), this);

        name2 = (EditText) findViewById(R.id.name2);
        pass2 = (EditText) findViewById(R.id.pass2);
        reg = (Button) findViewById(R.id.reg);
        gotoLogin = (Button) findViewById(R.id.gotoLogin);
    }

    @Override
    public void initDate() {
        reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String regname = name2.getText().toString();
                String regpass = pass2.getText().toString();
                if (regname.isEmpty()&&regpass.isEmpty()){
                    ToastUtils.showShort("信息不能为空");
                }else{
                    ip.mpRegiest(regname,regpass);//不为空向P层传值
                }

            }
        });
        /**
         * 发送粘性事件切换Fragment
         */
        gotoLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //发送粘性事件
                EventBus.getDefault().postSticky("直接登录");
            }
        });
    }

    @Override
    public void ShowReg(UserBean userBean) {
        if (userBean.getCode() == 0){
            ToastUtils.showShort("注册成功");
            //发送粘性事件
            EventBus.getDefault().postSticky("注册成功");
        }else {
            ToastUtils.showShort("注册失败");
        }    }

}
